package com.yangyang.jikehw.mr;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context)
            throws IOException, InterruptedException {

        long upSum = 0L;
        long downSum = 0L;

        for (FlowBean item : values) {
            upSum += item.getUpFlow();
            downSum += item.getDownFlow();
        }

        context.write(key, new FlowBean(upSum, downSum));
    }
}
